import socket

sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect(("localhost", 6677))
while True:
    data = input("请输入要发送的数据：")
    if data in ("q", "exit"):
        break

    sock.send(data.encode("utf-8"))
    data = sock.recv(1024)
    if len(data) == 0:
        print("服务器关闭了连接")
        break
    print("收到服务器返回的数据：", data.decode("utf-8"))

sock.close()
